﻿using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Extensions.Logging;
using System;

namespace Fall.Serilog
{
    /// <summary>
    /// 启用Serilog中间件，与官方文档一致
    /// </summary>
    public static class SerilogExtensions
    {
        /// <summary>
        /// 启用中间件
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="logger"></param>
        /// <param name="dispose"></param>
        /// <param name="providers"></param>
        /// <returns></returns>
        public static IHostBuilder UseFallSerilog(this IHostBuilder builder,
            ILogger logger = null,
            bool dispose = false,
            LoggerProviderCollection providers = null)
        {
            return builder.UseSerilog(logger, dispose, providers);
        }
        public static IHostBuilder UseFallSerilog(this IHostBuilder builder,
            Action<HostBuilderContext, LoggerConfiguration> configureLogger,
            bool preserveStaticLogger = false,
            bool writeToProviders = false)
        {
            return builder.UseSerilog(configureLogger, preserveStaticLogger, writeToProviders);
        }

        public static IHostBuilder UseFallSerilog(this IHostBuilder builder,
            Action<HostBuilderContext, IServiceProvider, LoggerConfiguration> configureLogger,
            bool preserveStaticLogger = false,
            bool writeToProviders = false)
        {
            return builder.UseSerilog(configureLogger, preserveStaticLogger, writeToProviders);
        }

    }
}
